package pure.csw.activemq.transaction;

import pure.csw.common.ActiveMqUtils;
import pure.csw.common.Constant;

import javax.jms.*;

public class Consumer {
    public static void main(String[] args) throws JMSException, InterruptedException {
        Connection connection = ActiveMqUtils.getConnection();
        connection.start();
        //获取一次会话
        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(Constant.QUEUENAME);
        MessageConsumer consumer = session.createConsumer(queue);
        System.out.println("等待消息接收...");
        while(true){
            TextMessage m = (TextMessage) consumer.receive();
            if (m != null){
                System.out.println(m.getText());
            }else{
                break;
            }
            //session.commit();
        }
        System.out.println("程序结束");
        session.close();
        consumer.close();
        connection.close();
    }
}
